// Copyright 2011 George Cook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#import "BaseTest.h"
#import <GHUnit/GHUnit.h>
#import "InjectivePropertyValueDescription.h"
#import "Injective.h"

@interface InjectivePropertyValueDescriptionTest : BaseTest
{
}

@end


@implementation InjectivePropertyValueDescriptionTest

- (void)testInit
{
	InjectivePropertyValueDescription *value = [[InjectivePropertyValueDescription alloc]
												initWithPropertyValue:@"test"
												withType:@"String"];
	GHAssertNotNil(value, @"initializer failed");
	GHAssertEqualStrings(value.propertyValueText, @"test", @"value not set");
	GHAssertEqualStrings(value.type, @"String", @"type not set");
}

- (void)testStringRealValue
{
	InjectivePropertyValueDescription *value = [[InjectivePropertyValueDescription alloc]
												initWithPropertyValue:@"test"
												withType:@"String"];
	NSString *stringValue = [value realValueUsingContainer:nil];
	GHAssertEqualStrings(stringValue, @"test", @"value was wrong");
}

- (void)testIntegerRealValue
{
	InjectivePropertyValueDescription *value = [[InjectivePropertyValueDescription alloc]
												initWithPropertyValue:@"21"
												withType:@"Integer"];
	NSNumber *numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue([numberValue isEqualToNumber: INJNINT(21)], @"value was wrong");
}

- (void)testNumberRealValue
{
	InjectivePropertyValueDescription *value = [[InjectivePropertyValueDescription alloc]
												initWithPropertyValue:@"21.2"
												withType:@"Float"];
	NSNumber *numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue([numberValue isEqualToNumber:INJNFLOAT(21.2)], @"value was wrong");
}

- (void)testBoolRealValue
{
	//YES
	InjectivePropertyValueDescription *value = [[InjectivePropertyValueDescription alloc]
												initWithPropertyValue:@"YES"
												withType:@"Bool"];
	NSNumber *numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue(INJNISYES(numberValue), @"value was not true");
	
	//TRUE
	value = [[InjectivePropertyValueDescription alloc]
			 initWithPropertyValue:@"TRUE"
			 withType:@"Bool"];
	numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue(INJNISYES(numberValue), @"value was not true");
	
	//NO
	value = [[InjectivePropertyValueDescription alloc]
			 initWithPropertyValue:@"NO"
			 withType:@"Bool"];
	numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue(INJNISNO(numberValue), @"value was not true");
	
	//FALSE
	value = [[InjectivePropertyValueDescription alloc]
			 initWithPropertyValue:@"FALSE"
			 withType:@"Bool"];
	numberValue = [value realValueUsingContainer:nil];
	GHAssertTrue(INJNISNO(numberValue), @"value was not true");
	
}

@end
